import Foundation
import Moya

//极光推送相关api
enum QiniuApi {
    case delete(token:String, encoded : String) //删除七牛云地址
    case upload(httpBody: Data,boundary:String)
    case download(url:String) //下载七牛云图片
}

extension QiniuApi: TargetType {
    var baseURL: URL {
        switch self {
        case .delete:
            return URL(string: "http://rs.qiniu.com/delete")!
        case .upload:
            return URL(string: "https://upload.qiniup.com")!
        case .download(let url):
            return URL(string: url)!
        }
    }
    
    var path: String {
        switch self {
        case .delete(_, let encoded):
            return "/\(encoded)"
        case .upload:
            return ""
        case .download:
            return ""
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .delete, .upload:
            return .post
        case .download:
            return .get
        }
    }
    
    var task: Task {
        switch self {
        case .delete:
            return .requestPlain
        case .upload(let body, _):
            return .requestData(body)
        case .download:
            return .requestPlain
        }
    }
    var headers: [String: String]? {
        var headers: [String: String] = [:]
        
        switch self {
        case .delete(let token, _):
            headers["Content-Type"] = "application/x-www-form-urlencoded"
            headers["Authorization"] = "\(token)"
            return headers
        case .upload(_, let boundary):
            headers["Content-Type"] = "multipart/form-data; boundary=\(boundary)"
            return headers
        case .download:
            return nil
        }
    }
    
    private var sampleData: Data? {
        // 通常用于模拟网络请求的响应数据
        return nil
    }
    
    var validate: Bool {
        return true  // 根据需要开启或关闭响应验证
    }
}
